package com.pmsystem.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.Village;
import com.pmsystem.service.VillageService;

/**
 * 
* <p>Title: VillageController</p>  
* <p>Description:处理小区信息的控制器 </p>  
* @author 树昌  
* @date 2019年1月18日
 */
@Controller
@RequestMapping("Information/")
public class VillageController {

	@Autowired
	VillageService villageService;
	
	/**
	 * 
	 * <p>Title: saveVillage</p>  
	 * <p>Description:添加保存小区的信息的控制器 </p>  
	 * @author 树昌
	 * @param village
	 * @return 跳转到显示所有小区信息的页面
	 */
	@RequestMapping(value="addvillage" ,method=RequestMethod.POST)
	public String saveVillage(Village village) {
		boolean row = villageService.addVillage(village);
		if(row) {
			return "Information/showvillage" ;
		}else {
			return "error";
		}
	}
	
	
	/**
	 * 
	 * <p>Title: showAllvillage</p>  
	 * <p>Description:显示所有小区的控制器 </p>  
	 * @author 树昌
	 * @return 不做跳转
	 */
	@RequestMapping(value="showallvillage" ,method=RequestMethod.POST)
	@ResponseBody
	public List<Village> showAllvillage(String keyword, Integer startRow, Integer pageSize) {

		return villageService.showVillage(keyword,startRow,pageSize);
	}
	
	
	/**
	 * 
	 * <p>Title: deleteVillage</p>  
	 * <p>Description:删除小区信息的控制器</p>  
	 * @author 树昌
	 * @return 不做跳转
	 */
	@RequestMapping(value="deletevillage" ,method=RequestMethod.POST)
	@ResponseBody
	public void deleteVillage(Village village) {
		villageService.deleteVillage(village);	
	}
	
	/**
	 * 
	 * <p>Title: updateVillage</p>  
	 * <p>Description:修改一条小区的信息的控制器 </p>  
	 * @author 树昌
	 * @param village
	 * @return 跳转到显示所有小区信息的页面
	 */
	@RequestMapping(value="updatevillage" ,method=RequestMethod.POST)
	public String updateVillage(Village village) {
		
		boolean row = villageService.updateVillage(village);
		if(row) {
			return "Information/showvillage";
		}else {
			return "error";
		}
	}
	
	
	@RequestMapping(value="deleteTable",method=RequestMethod.GET)
	public void deleteVillageTable() {
		villageService.deleteVillageTableData();
	}
	
}
